/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package net.ssta.core.util;

import java.io.PrintStream;
import java.util.List;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;

public class SmtpUtil
{

    public SmtpUtil(String smtp)
    {
        needAuth = false;
        username = "";
        password = "";
        setSmtpHost(smtp);
        createMimeMessage();
    }

    public void setSmtpHost(String hostName)
    {
        System.out.println((new StringBuilder("\u8BBE\u7F6E\u7CFB\u7EDF\u5C5E\u6027\uFF1Amail.smtp.host = ")).append(hostName).toString());
        if(props == null)
            props = System.getProperties();
        props.put("mail.smtp.host", hostName);
    }

    public boolean createMimeMessage()
    {
        try
        {
            System.out.println("\u51C6\u5907\u83B7\u53D6\u90AE\u4EF6\u4F1A\u8BDD\u5BF9\u8C61\uFF01");
            session = Session.getDefaultInstance(props, null);
        }
        catch(Exception e)
        {
            System.err.println((new StringBuilder("\u83B7\u53D6\u90AE\u4EF6\u4F1A\u8BDD\u5BF9\u8C61\u65F6\u53D1\u751F\u9519\u8BEF\uFF01")).append(e).toString());
            return false;
        }
        System.out.println("\u51C6\u5907\u521B\u5EFAMIME\u90AE\u4EF6\u5BF9\u8C61\uFF01");
        try
        {
            mimeMsg = new MimeMessage(session);
            mp = new MimeMultipart();
        }
        catch(Exception e)
        {
            System.err.println((new StringBuilder("\u521B\u5EFAMIME\u90AE\u4EF6\u5BF9\u8C61\u5931\u8D25\uFF01")).append(e).toString());
            return false;
        }
        return true;
    }

    public void setNeedAuth(boolean need)
    {
        System.out.println((new StringBuilder("\u8BBE\u7F6Esmtp\u8EAB\u4EFD\u8BA4\u8BC1\uFF1Amail.smtp.auth = ")).append(need).toString());
        if(props == null)
            props = System.getProperties();
        if(need)
            props.put("mail.smtp.auth", "true");
        else
            props.put("mail.smtp.auth", "false");
    }

    public void setNamePass(String name, String pass)
    {
        username = name;
        password = pass;
    }

    public boolean setSubject(String mailSubject)
    {
        System.out.println((new StringBuilder("\u8BBE\u7F6E\u90AE\u4EF6\u4E3B\u9898\uFF01")).append(mailSubject).toString());
        try
        {
            mimeMsg.setSubject(mailSubject);
        }
        catch(Exception e)
        {
            System.err.println("\u8BBE\u7F6E\u90AE\u4EF6\u4E3B\u9898\u53D1\u751F\u9519\u8BEF\uFF01");
            return false;
        }
        return true;
    }

    public boolean setBody(String mailBody)
    {
        try
        {
            BodyPart bp = new MimeBodyPart();
            bp.setContent((new StringBuilder("<meta http-equiv=Content-Type content=text/html; charset=gb2312>")).append(mailBody).toString(), "text/html;charset=GB2312");
            mp.addBodyPart(bp);
        }
        catch(Exception e)
        {
            System.err.println((new StringBuilder("\u8BBE\u7F6E\u90AE\u4EF6\u6B63\u6587\u65F6\u53D1\u751F\u9519\u8BEF\uFF01")).append(e).toString());
            return false;
        }
        return true;
    }

    public boolean addFileAffix(String filename)
    {
        System.out.println((new StringBuilder("\u589E\u52A0\u90AE\u4EF6\u9644\u4EF6\uFF1A")).append(filename).toString());
        try
        {
            BodyPart bp = new MimeBodyPart();
            FileDataSource fileds = new FileDataSource(filename);
            bp.setDataHandler(new DataHandler(fileds));
            bp.setFileName(fileds.getName());
            mp.addBodyPart(bp);
        }
        catch(Exception e)
        {
            System.err.println((new StringBuilder("\u589E\u52A0\u90AE\u4EF6\u9644\u4EF6\uFF1A")).append(filename).append("\u53D1\u751F\u9519\u8BEF\uFF01").append(e).toString());
            return false;
        }
        return true;
    }

    public boolean setFrom(String from)
    {
        System.out.println((new StringBuilder("\u8BBE\u7F6E\u53D1\u4FE1\u4EBA\uFF01")).append(from).toString());
        try
        {
            mimeMsg.setFrom(new InternetAddress(from));
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    public boolean setTo(String to)
    {
        if(to == null)
            return false;
        try
        {
            System.out.println((new StringBuilder("\u8BBE\u7F6E\u6536\u4EF6\u4EBA\uFF01")).append(to).toString());
            mimeMsg.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to));
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    public boolean setCopyTo(String copyto)
    {
        if(copyto == null)
            return false;
        try
        {
            System.out.println((new StringBuilder("\u8BBE\u7F6E\u6284\u9001\u4EBA\uFF01")).append(copyto).toString());
            mimeMsg.setRecipients(javax.mail.Message.RecipientType.CC, InternetAddress.parse(copyto));
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    public boolean setSecretCopyTo(String sct)
    {
        if(sct == null)
            return false;
        try
        {
            System.out.println((new StringBuilder("\u8BBE\u7F6E\u5BC6\u9001\u4EBA\uFF01")).append(sct).toString());
            mimeMsg.setRecipients(javax.mail.Message.RecipientType.BCC, InternetAddress.parse(sct));
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    public boolean sendout()
    {
        try
        {
            mimeMsg.setContent(mp);
            mimeMsg.saveChanges();
            System.out.println("\u6B63\u5728\u53D1\u9001\u90AE\u4EF6....");
            Session mailSession = Session.getInstance(props, null);
            Transport transport = mailSession.getTransport("smtp");
            transport.connect((String)props.get("mail.smtp.host"), username, password);
            if(mimeMsg.getRecipients(javax.mail.Message.RecipientType.TO) != null)
                transport.sendMessage(mimeMsg, mimeMsg.getRecipients(javax.mail.Message.RecipientType.TO));
            if(mimeMsg.getRecipients(javax.mail.Message.RecipientType.CC) != null)
                transport.sendMessage(mimeMsg, mimeMsg.getRecipients(javax.mail.Message.RecipientType.CC));
            if(mimeMsg.getRecipients(javax.mail.Message.RecipientType.BCC) != null)
                transport.sendMessage(mimeMsg, mimeMsg.getRecipients(javax.mail.Message.RecipientType.BCC));
            System.out.println("\u53D1\u9001\u90AE\u4EF6\u6210\u529F\uFF01");
            transport.close();
        }
        catch(Exception e)
        {
            System.err.println((new StringBuilder("\u90AE\u4EF6\u53D1\u9001\u5931\u8D25\uFF01")).append(e).toString());
            return false;
        }
        return true;
    }

    public static boolean sendMail(String smtpServer, String smtpUser, String smtpPass, String subject, String body, String from, String to, String cc, 
            String bcc, List fileList)
    {
        SmtpUtil themail = new SmtpUtil(smtpServer);
        themail.setNeedAuth(true);
        themail.setNamePass(smtpUser, smtpPass);
        themail.setSubject(subject);
        themail.setBody(body);
        themail.setTo(to);
        themail.setCopyTo(cc);
        themail.setSecretCopyTo(bcc);
        themail.setFrom(from);
        String fileStr = null;
        if(fileList != null && fileList.size() > 0)
        {
            for(int i = 0; i < fileList.size(); i++)
                fileStr = (String)fileList.get(i);

            themail.addFileAffix(fileStr);
        }
        return themail.sendout();
    }

    public boolean dlsendout(String dl)
    {
        if(dl == null)
            return false;
        try
        {
            mimeMsg.setContent(mp);
            mimeMsg.saveChanges();
            System.out.println("\u6B63\u5728\u53D1\u9001\u90AE\u4EF6....");
            Session mailSession = Session.getInstance(props, null);
            Transport transport = mailSession.getTransport("smtp");
            transport.connect((String)props.get("mail.smtp.host"), username, password);
            String to[] = dl.split(",");
            for(int i = 0; i < to.length; i++)
            {
                setTo(to[i]);
                System.out.println((new StringBuilder("\u72EC\u7ACB\u53D1\u9001\u7ED9")).append(to[i]).toString());
                transport.sendMessage(mimeMsg, mimeMsg.getRecipients(javax.mail.Message.RecipientType.TO));
            }

            System.out.println("\u53D1\u9001\u90AE\u4EF6\u6210\u529F\uFF01");
            transport.close();
        }
        catch(Exception e)
        {
            System.err.println((new StringBuilder("\u90AE\u4EF6\u53D1\u9001\u5931\u8D25\uFF01")).append(e).toString());
            return false;
        }
        return true;
    }

    public static boolean sendDLMail(String smtpServer, String smtpUser, String smtpPass, String subject, String body, String from, String to, List fileList)
    {
        SmtpUtil themail = new SmtpUtil(smtpServer);
        themail.setNeedAuth(true);
        themail.setNamePass(smtpUser, smtpPass);
        themail.setSubject(subject);
        themail.setBody(body);
        themail.setFrom(from);
        String fileStr = null;
        if(fileList != null && fileList.size() > 0)
        {
            for(int i = 0; i < fileList.size(); i++)
                fileStr = (String)fileList.get(i);

            themail.addFileAffix(fileStr);
        }
        return themail.dlsendout(to);
    }

    public static boolean sendDLMail(String smtpServer, String subject, String body, String from, String to, List fileList)
    {
        SmtpUtil themail = new SmtpUtil(smtpServer);
        themail.setNeedAuth(false);
        themail.setSubject(subject);
        themail.setBody(body);
        themail.setFrom(from);
        String fileStr = null;
        if(fileList != null && fileList.size() > 0)
        {
            for(int i = 0; i < fileList.size(); i++)
                fileStr = (String)fileList.get(i);

            themail.addFileAffix(fileStr);
        }
        return themail.dlsendout(to);
    }

    public static boolean sendMail(String smtpServer, String subject, String body, String from, String to, String cc, String bcc, List fileList)
    {
        SmtpUtil themail = new SmtpUtil(smtpServer);
        themail.setNeedAuth(false);
        themail.setSubject(subject);
        themail.setBody(body);
        themail.setTo(to);
        themail.setCopyTo(cc);
        themail.setSecretCopyTo(bcc);
        themail.setFrom(from);
        String fileStr = null;
        if(fileList != null && fileList.size() > 0)
        {
            for(int i = 0; i < fileList.size(); i++)
                fileStr = (String)fileList.get(i);

            themail.addFileAffix(fileStr);
        }
        return themail.sendout();
    }

    public static void main(String args[])
    {
        sendDLMail("smtp.163.com", "coverstory", "123654789", "\u72EC\u7ACB\u53D1\u9001\u8BD5\u9A8C", "sdsadsa", "coverstory@163.com", "mliz.hero@126.com,yangxi@icss.com.cn", null);
    }

    private MimeMessage mimeMsg;
    private Session session;
    private Properties props;
    private boolean needAuth;
    private String username;
    private String password;
    private Multipart mp;
}


/*
	DECOMPILATION REPORT

	Decompiled from: E:\workspace6.0\fsms\WebRoot\WEB-INF\lib\common.jar
	Total time: 172 ms
	Jad reported messages/errors:
Couldn't resolve all exception handlers in method dlsendout
	Exit status: 0
	Caught exceptions:
*/